<template>
  <div class="app-container">
    <el-tabs v-model="tabsRemark.activeName" @tab-click="tabsClick">
      <el-tab-pane
        :label="tabsRemark.onGoing"
        name="tabsRemark.nameA"
      ></el-tab-pane>
      <el-tab-pane
        :label="tabsRemark.inApproval"
        name="tabsRemark.nameB"
      ></el-tab-pane>
      <el-tab-pane
        :label="tabsRemark.history"
        name="tabsRemark.nameC"
      ></el-tab-pane>
    </el-tabs>
    <query></query>
    <el-table
      :data="loanManagementData"
      border
      fit
      highlight-current-row
      style="width: 100%"
      sort-change="dateSort"
    >
      <el-table-column
        align="center"
        sortable="custom"
        prop="loanVo.createdTime"
        :label="loanManagementRemark.createdTime"
        width="200"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.loanVo.createdTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="userVo.username"
        :label="loanManagementRemark.username"
        width="150"
      >
      </el-table-column>
      <el-table-column
        prop="userVo.phoneNumber"
        :label="loanManagementRemark.phoneNumber"
        width="160"
      >
      </el-table-column>
      <el-table-column
        prop="loanVo.totalMoney"
        :label="loanManagementRemark.totalMoney"
        width="150"
      >
      </el-table-column>
      <el-table-column
        prop="loanVo.paidMoney"
        :label="loanManagementRemark.paidMoney"
        width="150"
      >
      </el-table-column>
      <el-table-column :label="loanManagementRemark.type" min-width="70px">
        <template #default="{ row }">
          <el-tag>{{ row.loanVo.type }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="loanManagementRemark.status" min-width="70px">
        <template #default="{ row }">
          <el-tag>{{ row.loanVo.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :label="loanManagementRemark.operation"
        align="center"
        width="300"
        class-name="fixed-width"
      >
        <template #default="{ row }">
          <el-button type="primary" size="mini" @click="handleSeekInfo(row)">
            {{ loanManagementRemark.seek }}
          </el-button>
          <el-button size="mini" type="success" @click="correct(row.loanVo.id,true)">
            {{ loanManagementRemark.success }}
          </el-button>
          <el-button size="mini" type="danger" @click="correct(row.loanVo.id,false)">
            {{ loanManagementRemark.danger }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="pageData.total"
      v-show="pageData.total > 0"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageData.currentPage"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
    />
    <info-dialogue
      :isVisible="loanManagementRemark.InfoDialogueIsVisible"
      :InformationValue="loanManagementDataOne"
      @hide="InfoDialogueHide"
      @updateData="getData"
    ></info-dialogue>
  </div>
</template>

<script>
import InfoDialogue from "./InfoDialogue.vue";
import query from "./query/index.vue";

export default {
  components: {
    query,
    InfoDialogue,
  },

  data() {
    return {
      tabsRemark: {
        onGoing: "进行中",
        history: "历史记录",
        activeName: "onGoing",
        nameA: "onGoing",
        nameB: "history",
      },
      loanManagementRemark: {
        id: "ID",
        borrowId: "借款人ID",
        approverId: "贷款人ID",
        status: "状态",
        type: "贷款类型",
        totalMoney: "总额",
        paidMoney: "已还款额度",
        interestRate: "利率",
        createdTime: "贷款时间",
        username: "用户名",
        phoneNumber: "手机号",
        operation: "操作",
        seek: "查看信息",
        edit: "编辑",
        success: "审批通过",
        danger: "不通过",
        InfoDialogueIsVisible: false,
      },
      loanManagementData: [],
      loanManagementDataOne: {},
      pageData: {
        total: 10,
        page: 1,
        limit: 10,
        currentPage: 1,
      },
    };
  },
  created() {
    this.getData();
  },
  // mounted(){
  //   this.getData();
  // },
  methods: {
    tabsClick() {},
    getData() {
      this.$store
        .dispatch("request/get", "/basic/loan/query/management/list")
        .then((data) => {
          this.loanManagementData = data;
        });
    },
    handleSeekInfo(row) {
      this.loanManagementDataOne = row;
      this.loanManagementRemark.InfoDialogueIsVisible = true;
    },
    correct(loanId, flag) {
      let data = {
        loanId: loanId,
        ifPass: flag,
        url: "/basic/loan/update/status",
      };
      this.$store.dispatch("request/getP", data).then(() => {
        if (flag) {
          this.$message.success("审批通过");
        } else {
          this.$message.error("审批不通过");
        }
        this.getData();
      });
    },
    InfoDialogueHide() {
      this.loanManagementRemark.InfoDialogueIsVisible = false;
    },
    handleCurrentChange() {},
    handleSizeChange() {},
  },
};
</script>
